define(
	[
		'require',
		'./detail_nodedetail_track_ctrl'
	],
	function(require){
		var Controller = require('./detail_nodedetail_track_ctrl').extend({
			trackTitle: "错误交易",
			
			requireAlerts: function(params) {
				var ctrl = this,
					serviceId = ctrl.serviceId(),
					channelValue = this.get("channelValue"),
					typeValue = this.get("typeValue"),
					nodeId = ctrl.get("business").id,
					isTrue = ctrl.get("isTrue");
						
				var startDate = this.get("startDate"),
					endDate = this.get("endDate");

				if( isLocalDebugModel ){
					endDate = new Date(2014, 9, 1, 12, 0, 0);
					startDate = new Date(+endDate)
					startDate.setHours(startDate.getHours()-1);
				}

				if(typeValue == "交易类型"){
					typeValue = '';
				}
				if(channelValue == '交易渠道'){
					channelValue = '';
				}
		
				var params = {
					"appId":ctrl.get("business.id"),
					"keyWord": this.get("keyWord"),
				    "startDate": +startDate,
				    "pageIndex": this.get("pageIndex"),
				    "pageSize": this.get("pageSize"),
					"endDate": +endDate,
					"transactionChannel":channelValue,
					"transactionType": typeValue,
					"orderBy": this.get("orderBy"),
					"desc": this.get("desc")
				};
				//开发调试模式参数
				if( isLocalDebugModel ){
					params = undefined;
				}
		
				return ctrl.store.ajax("GET", "trades/error/trade/tracking", params)
				.then(function(response){
					var status = response.status;
					if(status != "success"){
						return
					};

					ctrl.set('isData',false);

					var alerts = response.result||[];
					alerts.forEach(function(node,index){
						node.sequence = index+1;
						if(node.isError){
							node.result = "失败";
						}else{
							node.result = "成功";
 						}
					});		

					if (alerts.length == 0) {
						ctrl.set("pageIndex",0);
						ctrl.set("pageSize",10);
						ctrl.set("totalRows",0);
						ctrl.set("pageCount",0);
					} else {
						ctrl.set("pageIndex",response.meta.pageIndex);
						ctrl.set("pageSize",response.meta.pageSize == 0?10:response.meta.pageSize);
						ctrl.set("totalRows",response.meta.total);
						ctrl.set("pageCount",response.meta.totalPage);
					}
					
					ctrl.set("alerts", alerts);
					return response;
				});
			}
		});

		APM.BusinessDetailNodedetailWrongtransactionController = Controller;
		return Controller;
	}
);